package leetcode;

/**
 * Created by Ghost on 2014/12/19 0019.
 */
public class Compare_Version_Numbers {
    public int compare(String[] v1, String[] v2, int curIdx){
        if(curIdx<v1.length && curIdx<v2.length){
            if(Integer.parseInt(v1[curIdx])==Integer.parseInt(v2[curIdx]))
                return compare(v1,v2,curIdx+1);
            else if(Integer.parseInt(v1[curIdx])>Integer.parseInt(v2[curIdx]))
                return 1;
            else
                return -1;
        }
        else if(curIdx<v1.length && curIdx==v2.length){
            if(Integer.parseInt(v1[curIdx])==0)
                return 0;
            else
                return 1;
        }
        else if(curIdx==v1.length && curIdx<v2.length){
            if(0==Integer.parseInt(v2[curIdx]))
                return 0;
            else
                return -1;
        }
        else
            return 0;
    }
    public int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");

        return compare(v1,v2,0);
    }

    public static void main(String[] args){
        Compare_Version_Numbers compareVersionNumbers = new Compare_Version_Numbers();
        System.out.println(compareVersionNumbers.compareVersion("01", "1"));
    }
}
